home *** CD-ROM | disk | FTP | other *** search
/ Draw 3 / Draw 3.iso / AOL90 / COMP03.000 / $_5_ / IMAlertPopup.swf / scripts / frame_1 / DoAction.as
Encoding:
Text File  |  2004-11-29  |  11.6 KB  |  407 lines

  1. function wait(time, func, count)
  2. {
  3.    __tempWaitInterval__ = setInterval(waitHelper,time,func,count);
  4. }
  5. function waitHelper(func, count)
  6. {
  7.    i++;
  8.    if(i - 1 < count)
  9.    {
  10.       func();
  11.    }
  12.    else
  13.    {
  14.       clearInterval(__tempWaitInterval__);
  15.    }
  16. }
  17. function Movement()
  18. {
  19.    var q = null;
  20.    var _interval_alpha = null;
  21.    var _this = this;
  22.    var xspeed = 0;
  23.    var yspeed = 0;
  24.    var xdif = 0;
  25.    var ydif = 0;
  26.    this.stopMove = function()
  27.    {
  28.       delete xspeed;
  29.       delete yspeed;
  30.       delete xdif;
  31.       delete ydif;
  32.       clearInterval(q);
  33.       _this.onStop();
  34.    };
  35.    this.stopMoveNoStop = function()
  36.    {
  37.       delete xspeed;
  38.       delete yspeed;
  39.       delete xdif;
  40.       delete ydif;
  41.       clearInterval(q);
  42.    };
  43.    this.moveBounce = function(x, y, object, speed, bounce)
  44.    {
  45.       q = setInterval(this.moveBouncePhase,41.666666666666664,x,y,object,speed,bounce);
  46.    };
  47.    this.moveOut = function(x, y, object, speed, bounce)
  48.    {
  49.       q = setInterval(this.moveOutPhase,41.666666666666664,x,y,object,speed);
  50.    };
  51.    this.moveBouncePhase = function(targetx, targety, object, a, b)
  52.    {
  53.       with(object)
  54.       {
  55.          xdif = targetx - _x;
  56.          xspeed += xdif / a;
  57.          xspeed *= b;
  58.          _x += xspeed;
  59.          ydif = targety - _y;
  60.          yspeed += ydif / a;
  61.          yspeed *= b;
  62.          _y += yspeed;
  63.          if(Math.abs(xspeed) < 0.52 && Math.abs(yspeed) < 0.52)
  64.          {
  65.             delete xspeed;
  66.             delete yspeed;
  67.             delete xdif;
  68.             delete ydif;
  69.             clearInterval(q);
  70.             _this.onStop();
  71.          }
  72.       }
  73.    };
  74.    this.moveOutPhase = function(targetx, targety, object, a)
  75.    {
  76.       with(object)
  77.       {
  78.          xdif = targetx - _x;
  79.          xspeed = xdif / a;
  80.          _x += xspeed;
  81.          ydif = targety - _y;
  82.          yspeed = ydif / a;
  83.          _y += yspeed;
  84.          if(Math.abs(xspeed) < 0.02 && Math.abs(yspeed) < 0.02)
  85.          {
  86.             delete xspeed;
  87.             delete yspeed;
  88.             delete xdif;
  89.             delete ydif;
  90.             clearInterval(q);
  91.             _this.onStop();
  92.          }
  93.       }
  94.    };
  95.    this.fadeOut = function(tar, gap)
  96.    {
  97.       clearInterval(_interval_alpha);
  98.       _interval_alpha = setInterval(this.fadeOutPhase,41.666666666666664,tar,gap);
  99.    };
  100.    this.fadeOutPhase = function(tar, gap)
  101.    {
  102.       if(tar._alpha > 50 && tar._alpha - gap <= 50)
  103.       {
  104.          _this.onFadedMidpoint();
  105.       }
  106.       tar._alpha -= gap;
  107.       if(tar._alpha - gap <= -10)
  108.       {
  109.          tat._alpha = 0;
  110.          clearInterval(_interval_alpha);
  111.          _this.onFaded();
  112.       }
  113.    };
  114.    this.fadeIn = function(tar, gap)
  115.    {
  116.       clearInterval(_interval_alpha);
  117.       _interval_alpha = setInterval(this.fadeInPhase,41.666666666666664,tar,gap);
  118.    };
  119.    this.fadeInPhase = function(tar, gap)
  120.    {
  121.       if(tar._alpha < 50 && tar._alpha + gap >= 50)
  122.       {
  123.          _this.onFadeinMidpoint();
  124.       }
  125.       tar._alpha += gap;
  126.       if(tar._alpha + gap >= 110)
  127.       {
  128.          tat._alpha = 100;
  129.          clearInterval(_interval_alpha);
  130.       }
  131.    };
  132.    this.stopFade = function()
  133.    {
  134.       clearInterval(_interval_alpha);
  135.    };
  136. }
  137. function UpdateIMAlert()
  138. {
  139.    strParsedArray = ParseNewIMXML(_level0.strIMAlert);
  140.    if(strParsedArray.length > 1)
  141.    {
  142.       UpdateAlert(strParsedArray[0],strParsedArray[1]);
  143.    }
  144. }
  145. function UpdateKnockAlert()
  146. {
  147.    if(_level0.strKnockFlags == 0)
  148.    {
  149.       _level0.IMMessage_str = _level0.strKnockAlert;
  150.       if(_level0.mcIMAlert.IMMessage_txt.textWidth > _level0.mcIMAlert.IMMessage_txt._width)
  151.       {
  152.          _level0.IMMessage_str += "...";
  153.          while(_level0.IMMessage_str.length > 0 && mcIMAlert.IMMessage_txt.textWidth > mcIMAlert.IMMessage_txt._width)
  154.          {
  155.             _level0.IMMessage_str = _level0.IMMessage_str.substr(0,_level0.IMMessage_str.length - 4) + "...";
  156.          }
  157.          strKnockSN = _level0.IMMessage_str;
  158.       }
  159.       else
  160.       {
  161.          strKnockSN = _level0.strKnockAlert;
  162.       }
  163.    }
  164.    else
  165.    {
  166.       strKnockSN = STR_KNOCKKNOCK_NOUSER;
  167.    }
  168.    var strKnockTitle = STR_KNOCKKNOCK_TITLE;
  169.    var nPoundIndex = STR_KNOCKKNOCK_TITLE.indexOf("#");
  170.    if(nPoundIndex < STR_KNOCKKNOCK_TITLE.length)
  171.    {
  172.       strKnockTitle = STR_KNOCKKNOCK_TITLE.substr(0,nPoundIndex) + _level0.nKnockIndex + STR_KNOCKKNOCK_TITLE.substr(nPoundIndex + 1,STR_KNOCKKNOCK_TITLE.length - nPoundIndex);
  173.    }
  174.    UpdateAlert(strKnockTitle,strKnockSN + " " + STR_KNOCKKNOCK_DEFAULTMSG);
  175. }
  176. function ParseNewIMXML(strIMXML)
  177. {
  178.    strParsedArray = new Array();
  179.    lastIMXml = new XML();
  180.    lastIMXml.ignoreWhite = true;
  181.    lastIMXml.parseXML(strIMXML);
  182.    listNode = lastIMXml.firstChild;
  183.    if(listNode.nodeName == "im")
  184.    {
  185.       strScreenName = "";
  186.       strWaiting = "";
  187.       strMessage = "";
  188.       nIMCounter = 0;
  189.       while(nIMCounter < listNode.childNodes.length)
  190.       {
  191.          itemNode = listNode.childNodes[nIMCounter];
  192.          if(itemNode.nodeName == "sender")
  193.          {
  194.             textNode = itemNode.firstChild;
  195.             strScreenName = textNode.nodeValue;
  196.          }
  197.          else if(itemNode.nodeName == "waiting")
  198.          {
  199.             textNode = itemNode.firstChild;
  200.             if(textNode.nodeValue == "yes")
  201.             {
  202.                strWaiting = "yes";
  203.             }
  204.          }
  205.          else if(itemNode.nodeName == "message")
  206.          {
  207.             textNode = itemNode.firstChild;
  208.             strMessage = textNode.nodeValue;
  209.          }
  210.          nIMCounter++;
  211.       }
  212.       strParsedArray = new Array(strScreenName,strMessage);
  213.    }
  214.    return strParsedArray;
  215. }
  216. function nextCRLF(strSearchString, nStartIndex)
  217. {
  218.    nNextCRLF = -1;
  219.    nReturnIndex = strSearchString.indexOf("\r",nStartIndex);
  220.    nNewLineIndex = strSearchString.indexOf("\n",nStartIndex);
  221.    if(nReturnIndex > -1)
  222.    {
  223.       if(nNewLineIndex > -1)
  224.       {
  225.          nNextCRLF = Math.min(nReturnIndex,nNewLineIndex);
  226.       }
  227.       else
  228.       {
  229.          nNextCRLF = nReturnIndex;
  230.       }
  231.    }
  232.    else
  233.    {
  234.       nNextCRLF = nNewLineIndex;
  235.    }
  236.    return nNextCRLF;
  237. }
  238. function prevWhitespace(strSearchString, nStartIndex, bExcludeCRLF)
  239. {
  240.    nPrevWhitespace = -1;
  241.    if(nStartIndex >= strSearchString.length)
  242.    {
  243.       nStartIndex = strSearchString.length;
  244.    }
  245.    if(bExcludeCRLF)
  246.    {
  247.       arrayOfWhitespace = new Array(" ","\t");
  248.    }
  249.    else
  250.    {
  251.       arrayOfWhitespace = new Array(" ","\r","\n","\t");
  252.    }
  253.    i = 0;
  254.    while(i < arrayOfWhitespace.length)
  255.    {
  256.       strSearchChar = arrayOfWhitespace[i];
  257.       nIndexChar = strSearchString.lastIndexOf(strSearchChar,nStartIndex);
  258.       if(nIndexChar > -1)
  259.       {
  260.          if(nPrevWhitespace == -1)
  261.          {
  262.             nPrevWhitespace = nIndexChar;
  263.          }
  264.          else if(nIndexChar < nPrevWhitespace)
  265.          {
  266.             nPrevWhitespace = nIndexChar;
  267.          }
  268.       }
  269.       i++;
  270.    }
  271.    return nPrevWhitespace;
  272. }
  273. function StringFitsInField(strSomeString, txtSomeTextField)
  274. {
  275.    var bResult = false;
  276.    txtSomeTextField.text = strSomeString;
  277.    trace("[" + strSomeString + "] txtSomeTextField.textWidth=" + txtSomeTextField.textWidth + "|txtSomeTextField._width=" + txtSomeTextField._width);
  278.    if(txtSomeTextField._width > txtSomeTextField.textWidth)
  279.    {
  280.       bResult = true;
  281.    }
  282.    return bResult;
  283. }
  284. function UpdateAlert(strScreenName, strNewText)
  285. {
  286.    clearInterval(closureTimer);
  287.    closureTimer = setInterval(CloseAlert,1000 * nPreferredDuration);
  288.    fademovement.stopFade();
  289.    mcIMAlert._alpha = 100;
  290.    mcIMAlert.IMMessage_txt._visible = true;
  291.    _level0.ScreenName_str = strScreenName;
  292.    if(mcIMAlert.ScreenName_txt.textWidth > mcIMAlert.ScreenName_txt._width)
  293.    {
  294.       _level0.ScreenName_str += "...";
  295.       while(_level0.ScreenName_str.length > 0 && mcIMAlert.ScreenName_txt.textWidth > mcIMAlert.ScreenName_txt._width)
  296.       {
  297.          _level0.ScreenName_str = _level0.ScreenName_str.substr(0,_level0.ScreenName_str.length - 4) + "...";
  298.       }
  299.    }
  300.    var nLineCount = 0;
  301.    var nParseIndex = 0;
  302.    var strMessage = "";
  303.    while(nLineCount < INT_IMALERT_MAXLINES && nParseIndex < strNewText.length)
  304.    {
  305.       var nReturnIndex = nextCRLF(strNewText,nParseIndex);
  306.       var strTextUpToReturn = strNewText.substr(nParseIndex,nReturnIndex - nParseIndex);
  307.       if(nReturnIndex >= nParseIndex && StringFitsInField(strTextUpToReturn,_level0.mcIMAlert.IMMessage_txt))
  308.       {
  309.          strMessage += strTextUpToReturn + "\r";
  310.          nParseIndex = nReturnIndex + 1;
  311.       }
  312.       else
  313.       {
  314.          var strTextRemaining = strNewText.substr(nParseIndex,strNewText.length - nParseIndex);
  315.          if(StringFitsInField(strTextRemaining,_level0.mcIMAlert.IMMessage_txt))
  316.          {
  317.             strMessage += strTextRemaining;
  318.             nParseIndex = strNewText.length;
  319.          }
  320.          else
  321.          {
  322.             var nSpaceIndex = -1;
  323.             var nBreakIndex = nParseIndex + 1;
  324.             var strTextUpToBreak = strNewText.substr(nParseIndex,nBreakIndex - nParseIndex);
  325.             while(nBreakIndex < strNewText.length && StringFitsInField(strTextUpToBreak,_level0.mcIMAlert.IMMessage_txt))
  326.             {
  327.                cBreakCharacter = strNewText.charAt(nBreakIndex);
  328.                if(cBreakCharacter == " " || cBreakCharacter == "\t")
  329.                {
  330.                   nSpaceIndex = nBreakIndex;
  331.                }
  332.                nBreakIndex++;
  333.                strTextUpToBreak = strNewText.substr(nParseIndex,nBreakIndex - nParseIndex);
  334.             }
  335.             if(nBreakIndex - 1 > nParseIndex && nBreakIndex < strNewText.length)
  336.             {
  337.                var nFinalBreakIndex = nBreakIndex - 1;
  338.                if(nSpaceIndex > -1)
  339.                {
  340.                   nFinalBreakIndex = nSpaceIndex;
  341.                }
  342.                strMessage += strNewText.substr(nParseIndex,nFinalBreakIndex - nParseIndex) + "\r";
  343.                nParseIndex = nFinalBreakIndex;
  344.                if(nSpaceIndex > -1)
  345.                {
  346.                   nParseIndex++;
  347.                }
  348.             }
  349.          }
  350.       }
  351.       nLineCount++;
  352.    }
  353.    if(nParseIndex < strNewText.length)
  354.    {
  355.       strMessage = strMessage.substr(0,strMessage.length - 3) + "...";
  356.    }
  357.    _level0.IMMessage_str = strMessage;
  358. }
  359. function CloseAlert()
  360. {
  361.    clearInterval(closureTimer);
  362.    fademovement = new Movement();
  363.    fademovement.fadeOut(mcIMAlert,INT_IMALERT_FADESPEED);
  364.    fademovement.onFadedMidpoint = function()
  365.    {
  366.       mcIMAlert.IMMessage_txt._visible = false;
  367.    };
  368.    fademovement.onFaded = function()
  369.    {
  370.       fscommand("close");
  371.    };
  372. }
  373. STR_IMALERT_OPENIM = "Open IM";
  374. STR_KNOCKKNOCK_TITLE = "Knock Knock #!";
  375. STR_KNOCKKNOCK_DEFAULTMSG = "sent you a message from outside the AOL Service.";
  376. STR_KNOCKKNOCK_NOUSER = "An Internet User";
  377. INT_IMALERT_DURATION = 4;
  378. INT_IMALERT_MAXLINES = 3;
  379. INT_IMALERT_FADESPEED = 10;
  380. mcIMAlert._alpha = 0;
  381. fademovement = new Movement();
  382. fademovement.fadeIn(mcIMAlert,INT_IMALERT_FADESPEED);
  383. fademovement.onFadeinMidpoint = function()
  384. {
  385.    mcIMAlert.IMMessage_txt._visible = true;
  386. };
  387. fademovement.onFaded = function()
  388. {
  389.    mcIMAlert._alpha = 100;
  390. };
  391. nPreferredDuration = INT_IMALERT_DURATION;
  392. closureTimer = setInterval(CloseAlert,1000 * nPreferredDuration);
  393. _level0.OpenIMButtonText = STR_IMALERT_OPENIM;
  394. mcIMAlert.OpenIM_btn.onRelease = function()
  395. {
  396.    fscommand("GoToIMForSN",ScreenName_str);
  397.    fscommand("close");
  398. };
  399. mcIMAlert.OpenIM_btn.onKeyDown = function()
  400. {
  401.    if(Key.getCode() == 13 || Key.getCode() == 32)
  402.    {
  403.       mcIMAlert.OpenIM_btn.onRelease();
  404.    }
  405. };
  406. stop();
  407.